import 'dart:convert';
import 'package:ichinesereader/models/common/LevelProgress.dart';
import 'package:ichinesereader/models/common/Settings.dart';
import 'package:ichinesereader/models/common/MyAchievement.dart';
import 'package:ichinesereader/models/student/PlayerLevelClass.dart';
import 'package:ichinesereader/models/student/AssessmentProgress.dart';
import 'package:ichinesereader/models/class/ClassResp.dart';

ProfileStudent profileStudentFromJson(String str) =>
    ProfileStudent.fromJson(json.decode(str));

String profileStudentToJson(ProfileStudent data) => json.encode(data.toJson());

class ProfileStudent {
  ProfileStudent({
    this.userId,
    this.userName,
    this.email,
    this.firstName,
    this.lastName,
    this.role,
    this.disabled,
    this.timestampDisabled,
    this.timestampEnabled,
    this.timestampCreated,
    this.timestampPasswordChanged,
    this.profileImageUrl,
    this.settings,
    this.deleted,
    this.lastLoggedIn,
    this.lastLogIn,
    this.accessCode,
    this.worldRank,
    this.race,
    this.programType,
    this.gender,
    this.nickName,
    this.birthDay,
    this.dateOfBirth,
    this.parentEmail,
    this.points,
    this.playerLevel,
    this.pointsCollected,
    this.pointsSpent,
    this.language,
    this.myAchievements,
    this.levelProgress,
    this.assessmentProgress,
    this.gameLevel,
    this.levelPercentage,
    this.excludeFromLeaderboard,
    this.gameDisable,
    this.numBooks,
    this.numQuizzes,
    this.totalLoginTime,
    this.totalGameTime,
    this.bookRead30Days,
    this.bookRead7Days,
    this.quizTaken30Days,
    this.quizTaken7Days,
    this.createDateInDateFormat,
    this.linkTime,
    this.assessmentShortName,
    this.level,
    this.classNames,
    this.noOfClasses,
    this.classResps,
    this.schoolName,
    this.theme,
    this.lang,
    this.profileStudentFromJson,
  });

  String? userId;
  String? userName;
  dynamic email;
  String? firstName;
  String? lastName;
  List<String>? role;
  bool? disabled;
  dynamic timestampDisabled;
  dynamic timestampEnabled;
  int? timestampCreated;
  int? timestampPasswordChanged;
  dynamic profileImageUrl;
  Settings? settings;
  bool? deleted;
  int? lastLoggedIn;
  dynamic lastLogIn;
  String? accessCode;
  int? worldRank;
  dynamic race;
  dynamic programType;
  String? gender;
  String? nickName;
  dynamic birthDay;
  dynamic dateOfBirth;
  dynamic parentEmail;
  int? points;
  PlayerLevelClass? playerLevel;
  int? pointsCollected;
  int? pointsSpent;
  String? language;
  List<MyAchievement>? myAchievements;
  LevelProgress? levelProgress;
  //dynamic levelProgress;
  AssessmentProgress? assessmentProgress;
  int? gameLevel;
  int? levelPercentage;
  bool? excludeFromLeaderboard;
  bool? gameDisable;
  int? numBooks;
  int? numQuizzes;
  int? totalLoginTime;
  int? totalGameTime;
  int? bookRead30Days;
  int? bookRead7Days;
  int? quizTaken30Days;
  int? quizTaken7Days;
  dynamic createDateInDateFormat;
  int? linkTime;
  dynamic assessmentShortName;
  String? level;
  dynamic classNames;
  int? noOfClasses;
  List<ClassResp>? classResps;
  String? schoolName;
  int? theme;
  int? lang;
  bool? profileStudentFromJson;
  int? quizThreshold;

  factory ProfileStudent.fromJson(Map<String, dynamic> json) => ProfileStudent(
        userId: json["userId"],
        userName: json["userName"],
        email: json["email"],
        firstName: json["firstName"],
        lastName: json["lastName"],
        role: json["role"] != null
            ? List<String>.from(json["role"].map((x) => x))
            : null,
        disabled: json["disabled"],
        timestampDisabled: json["timestampDisabled"],
        timestampEnabled: json["timestampEnabled"],
        timestampCreated: json["timestampCreated"],
        timestampPasswordChanged: json["timestampPasswordChanged"],
        profileImageUrl: json["profileImageUrl"],
        settings: json["settings"] != null
            ? Settings.fromJson(json["settings"])
            : null,
        deleted: json["deleted"],
        lastLoggedIn: json["lastLoggedIn"],
        lastLogIn: json["lastLogIn"],
        accessCode: json["accessCode"],
        worldRank: json["worldRank"],
        race: json["race"],
        programType: json["programType"],
        gender: json["gender"],
        nickName: json["nickName"],
        birthDay: json["birthDay"],
        dateOfBirth: json["dateOfBirth"],
        parentEmail: json["parentEmail"],
        points: json["points"],
        playerLevel: json["playerLevel"] != null
            ? PlayerLevelClass.fromJson(json["playerLevel"])
            : null,
        pointsCollected: json["pointsCollected"],
        pointsSpent: json["pointsSpent"],
        language: json["language"],
        myAchievements: json["myAchievements"] != null
            ? List<MyAchievement>.from(
                json["myAchievements"].map((x) => MyAchievement.fromJson(x)))
            : null,
        levelProgress: json["levelProgress"] != null
            ? LevelProgress.fromJson(json["levelProgress"])
            : null,
        //levelProgress:json["levelProgress"],
        assessmentProgress: json["assessmentProgress"] != null
            ? AssessmentProgress.fromJson(json["assessmentProgress"])
            : null,
        gameLevel: json["gameLevel"],
        levelPercentage: json["levelPercentage"],
        excludeFromLeaderboard: json["excludeFromLeaderboard"],
        gameDisable: json["gameDisable"],
        numBooks: json["numBooks"],
        numQuizzes: json["numQuizzes"],
        totalLoginTime: json["totalLoginTime"],
        totalGameTime: json["totalGameTime"],
        bookRead30Days: json["bookRead30Days"],
        bookRead7Days: json["bookRead7Days"],
        quizTaken30Days: json["quizTaken30Days"],
        quizTaken7Days: json["quizTaken7Days"],
        createDateInDateFormat: json["createDateInDateFormat"],
        linkTime: json["linkTime"],
        assessmentShortName: json["assessmentShortName"],
        level: json["level"],
        classNames: json["classNames"],
        noOfClasses: json["noOfClasses"],
        classResps: json["classResps"] != null
            ? List<ClassResp>.from(
                json["classResps"].map((x) => ClassResp.fromJson(x)))
            : null,
        schoolName: json["schoolName"],
        theme: json["theme"] ?? 0,
        lang: json["lang"] ?? 0,
      );

  Map<String, dynamic> toJson() => {
        "userId": userId,
        "userName": userName,
        "email": email,
        "firstName": firstName,
        "lastName": lastName,
        "role": role != null ? List<dynamic>.from(role!.map((x) => x)) : null,
        "disabled": disabled,
        "timestampDisabled": timestampDisabled,
        "timestampEnabled": timestampEnabled,
        "timestampCreated": timestampCreated,
        "timestampPasswordChanged": timestampPasswordChanged,
        "profileImageUrl": profileImageUrl,
        "settings": settings != null ? settings?.toJson() : null,
        "deleted": deleted,
        "lastLoggedIn": lastLoggedIn,
        "lastLogIn": lastLogIn,
        "accessCode": accessCode,
        "worldRank": worldRank,
        "race": race,
        "programType": programType,
        "gender": gender,
        "nickName": nickName,
        "birthDay": birthDay,
        "dateOfBirth": dateOfBirth,
        "parentEmail": parentEmail,
        "points": points,
        "playerLevel": playerLevel != null ? playerLevel?.toJson() : null,
        "pointsCollected": pointsCollected,
        "pointsSpent": pointsSpent,
        "language": language,
        "myAchievements": myAchievements != null
            ? List<dynamic>.from(myAchievements!.map((x) => x.toJson()))
            : null,
        "levelProgress": levelProgress != null ? levelProgress?.toJson() : null,
        //"levelProgress": levelProgress,
        "assessmentProgress":
            assessmentProgress != null ? assessmentProgress?.toJson() : null,
        "gameLevel": gameLevel,
        "levelPercentage": levelPercentage,
        "excludeFromLeaderboard": excludeFromLeaderboard,
        "gameDisable": gameDisable,
        "numBooks": numBooks,
        "numQuizzes": numQuizzes,
        "totalLoginTime": totalLoginTime,
        "totalGameTime": totalGameTime,
        "bookRead30Days": bookRead30Days,
        "bookRead7Days": bookRead7Days,
        "quizTaken30Days": quizTaken30Days,
        "quizTaken7Days": quizTaken7Days,
        "createDateInDateFormat": createDateInDateFormat,
        "linkTime": linkTime,
        "assessmentShortName": assessmentShortName,
        "level": level,
        "classNames": classNames,
        "noOfClasses": noOfClasses,
        "classResps": classResps != null
            ? List<dynamic>.from(classResps!.map((x) => x.toJson()))
            : null,
        "schoolName": schoolName,
        "theme": theme,
        "lang": lang,
      };
}
